<?php


namespace App\Transformers\Store;


use App\Models\LiveAnchor;
use App\Models\StoreBargainUser;
use App\Transformers\User\UserTransformer;
use League\Fractal\TransformerAbstract;

class StoreBargainUserTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['storeBargain','user'];

    public function transform(StoreBargainUser $data)
    {
        return [
            'id' => $data->id,
            'bargain_id' => $data->bargain_id ?? "",
            'user_id' => $data->user_id ?? "",
            'bargain_price_min' => $data->bargain_price_min ?? "",
            'bargain_price' => $data->bargain_price ?? "",
            'price' => $data->price ?? "",
            'status' => $data->statusEnum[$data->status] ?? "",
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    /**
     *额外包含砍价商品数据
     */

    public function includeStoreBargain(StoreBargainUser $storeBargainUser)
    {
        return $this->item($storeBargainUser->storeBargain, new StoreBargainTransformer());
    }

    /**
     *额外包含用户数据
     */

    public function includeUser(StoreBargainUser $storeBargainUser)
    {
        return $this->item($storeBargainUser->user, new UserTransformer());
    }
}
